import random

symbols = '$¢£¥€¤'
codes = [ord(symbol) for symbol in symbols]
print(codes)

x = 'ABC'
codes = [last := ord(c) for c in x]
print(last)
# :=会保存局部变量，last可再使用而c不行！

symbols = '$¢£¥€¤'
beyond_ascii = [ord(s) for s in symbols if ord(s) > 127]  # 推荐！
# beyond_ascii = list(filter(lambda c: c > 127, map(ord, symbols)))
print(beyond_ascii)
# 两种不同的生成方式

colors = ['black', 'white']
sizes = ['S', 'M', 'L']
tshirts = [(color, size) for color in colors for size in sizes]
# 笛卡尔积，双重循环

t = tuple(ord(symbol) for symbol in symbols)  # 可以省略两层括号为一层
import array
b = array.array('I', (ord(symbol) for symbol in symbols))
# 好处：不用像listcomp生成一个完整的list，而是直接按这种规则生成，节省内存

tri_ls = [[[random.random() for _ in range(4)] for _ in range(3)] for _ in range(5)]
result = [third_inner * 10 for first_inner in tri_ls for second_inner in first_inner for third_inner in second_inner]
# 多重写法：在最左侧插入